<?php
namespace app\common\order\model;

use app\common\system\logic\UserLogic;
use think\Model;
use think\model\concern\SoftDelete;

class Suborder extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;
    
    protected $type = [];

    public function getUserAttr($value, $data) {
        $userLogic = new UserLogic();
        return $userLogic->getUser($data['user_id'], ['id', 'realname', 'work_wechat']);
    }

    // order bom
    public function getBomAttr($value, $data) {
        $model = new SuborderBom();
        $bom = $model->where('suborder_id', $data['id'])->hidden(['create_time', 'update_time', 'delete_time'])->select();

        return $bom;
    }

    public function generateSuborderNo() {
        return 'E' . date('YmdHis') . rand(1000, 9999);
    }
}